﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace HWR_Ants.Classes.Obsolete_2
{
    [Obsolete]
    class PheromonTable
    {
        double[,] pheromonMatrix;

        int citiesCount;

        public PheromonTable(IList<Point> ListOfCities, double initialPheromonWert)
        {
            citiesCount = ListOfCities.Count;
            pheromonMatrix = new double[citiesCount, citiesCount];
            fillMatrix(ListOfCities, initialPheromonWert);
        }

        public double[,] PheromonMatrix
        {
            get { return pheromonMatrix; }
            set { pheromonMatrix = value; }
        }

        private void fillMatrix(IList<Point> loc, double initialPheromons)
        {
            for (int i = 0; i < loc.Count; i++)
            {
                for (int j = 0; j < loc.Count; j++)
                {
                    if (i == j)
                        pheromonMatrix[i, j] = 0;
                    else
                        pheromonMatrix[i, j] = initialPheromons;
                    // erstmal nur 1 setzen 
                    // pheromonMatrix[i,j] = getPheromonStatus(initialPheromons, loc.ElementAt(i), loc.ElementAt(j));
                }
            }
        }

        private double getPheromonStatus(double initialPheromons, Point point, Point point_2)
        {
            if (point != point_2)
                return (initialPheromons / pythagoras(point, point_2));
            else
                return 0;
        }

        private double pythagoras(Point X, Point Y)
        {
            Point Z = new Point(Y.X, X.Y);
            int length_X_Z = Math.Abs(X.X - Z.X);
            int length_Y_Z = Math.Abs(Y.Y - Z.Y);
            double ret = Math.Sqrt(Math.Pow((double)length_X_Z, 2) + Math.Pow((double)length_Y_Z, 2));
            return ret;
        }

        public void UpdatePheromonStatus(double[,] pheromonTableValues)
        {
            for (int i = 0; i < citiesCount; i++)
            {
                for (int j = 0; j < citiesCount; j++)
                {
                    if (i != j)
                    {
                        pheromonMatrix[i, j] = (1 - Tools.Tools.ActiveCurrentOptions.Parameter.Rho) * pheromonMatrix[i, j];
                        pheromonMatrix[i, j] += pheromonTableValues[i, j];
                    }
                }
            }
        }
    }
}
